package com.syr;

public class StudentTest {
    public static void main(String[] args) {
        Student s = new Student();
        try {
            s.register(-100);
            System.out.println(s);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

    }
}
class Student {

    private int id;

    public void register(int id) {
        if (id > 0) {
            this.id = id;
        } else {
            //手动抛出异常对象
            throw new MyException("您输入的数据非法");
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                '}';
    }
}
